<template>
    <div class="contentmain">
        <el-row>
            <el-col :span="24">
                <el-button type="danger" icon="el-icon-plus" @click="newadd">添加抢购活动</el-button>
            </el-col>
        </el-row>
        <!-- 新增 -->
        <el-row>
            <el-col :span="24">
                <el-table class="table-data" :data="td" style="width: 100%;margin-top: 20px"
                    v-loading="loading"
                    element-loading-text="数据加载中..." >
                    <el-table-column label="抢购图片" >
                        <template slot-scope="scope">
                            <img :src="scope.row.rushImage" style="width: 100px;vertical-align: middle;">
                        </template>
                    </el-table-column>
                    <el-table-column prop="rushTitle" label="抢购标题" ></el-table-column>
                    <el-table-column prop="totalNum" label="总数量" ></el-table-column>
                    <el-table-column prop="limitNum" label="限购数量" ></el-table-column>
                    <el-table-column prop="remainNum" label="剩余数量" ></el-table-column>
                    <el-table-column prop="rushPrice" label="抢购价" ></el-table-column>
                    <el-table-column label="开始时间" >
                        <template slot-scope="scope">
                            {{scope.row.beginTime | format}}
                        </template>
                    </el-table-column>
                    <el-table-column label="结束时间" >
                        <template slot-scope="scope">
                            {{scope.row.endTime | format}}
                        </template>
                    </el-table-column>
                    <el-table-column label="操作" >
                        <template slot-scope="scope">
                            <el-button size="mini" @click="handleEdit(scope.$index, scope.row)">编辑</el-button>
                            <el-button size="mini" type="danger" @click="handleDelete(scope.$index, scope.row)">删除</el-button>
                        </template>
                    </el-table-column>
                </el-table>
            </el-col>
        </el-row>
        <!-- 表格 -->
        <!-- <el-row>
            <el-col :span="8" :offset="16">
                <el-pagination
                    @size-change="handleSizeChange"
                    @current-change="handleCurrentChange"
                    :current-page="currentPage"
                    :page-size="10"
                    layout="total, prev, pager, next, jumper"
                    :total="pagecount">
                </el-pagination>
            </el-col>
        </el-row> -->
        <!-- 分页 -->
        <CouTimes />
        <!-- dialog -->
    </div>
</template>
<script>
import moment from 'moment'
import CouTimes from 'components/Coupon/CouTimes'
export default {
    data(){
        return {
            td:[],
            loading:false,
            currentPage:1,
            pagecount:0
        }
    },
    components:{
        CouTimes
    },
    filters:{
        format(v){//入参时间戳,返回正常时间
            return moment(v).format("YYYY-MM-DD a h:mm:ss")
        }
    },
    computed:{
        getdialog(){
            return this.$store.state.coutimedialog
        }
    },
    watch:{
        getdialog(v){//获取弹窗信息
            if(!v){
                this.$store.state.coutimedialog=true
                this.getData()
            }
        }
    },
    mounted(){
        this.getData()
    },
    methods:{
        newadd(){//新增
            this.$store.commit('ChangeCouTime')
        },
        handleEdit(i,r){//修改带参数请求弹窗
            this.$store.commit('ChangeCouTime',r)
        },
        handleDelete(i,r){//删除
            var _this=this
            this.$confirm('此操作将永久删除该文件, 是否继续?', '提示', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                type: 'warning'
            }).then(() => {
                var pp=new URLSearchParams()
                pp.append('rushId',r.rushId)
                axios.get('/deleteGoodsRush.do',{params:pp}).then(r=>{
                    if(r.data.code==200){
                        _this.$message({
                            type: 'success',
                            message: '删除成功!'
                        });
                        _this.getData()
                    }else{
                        _this.$message.error(r.data.message)
                    }
                })
                
            }).catch(() => {});
        },
        handleSizeChange(i){//翻页
            this.topage(i)
        },
        handleCurrentChange(i){//翻页
            this.topage(i)
        },
        topage(i){//翻页
            var pp=new URLSearchParams()
            pp.append()
            this.getData(pp)
        },
        getData(v){//获取数据
            if(!this.$store.state.shiro){
                return
            }
            var _this=this
            axios.get('/listGoodsRush.do').then(r=>{
                if(r.data.code==200){
                    _this.td=[].concat(r.data.response.goodsRushList)
                    // _this.pagecount=r.data.response
                }else{
                    if(r.data.message=="not login"&&r.data.code==500){
                        _this.$message.error("访问者,请登录")
                        router.push('/Login');
                        return
                    }
                    _this.$message.error(r.data.message)
                }
            })
        }
    },
    beforeCreate(){
        if(!this.$store.state.shiro){
            _this.$router.push('/full')
        }
    }
}
</script>
